function checkForms(e) {
	var isvalid = true;
	
	var username = document.getElementsByName("username")[0].value;
	var password = document.getElementsByName("password")[0].value;
	var confirmpassword = document.getElementsByName("confirmpassword")[0].value;
	var nama = document.getElementsByName("nama")[0].value;
	var tanggal = document.getElementsByName("tanggal")[0].value;
	var email = document.getElementsByName("email")[0].value;
		
	// check field username	
	if (!username.match(/^[A-Za-z0-9_.]{5,}$/i)){
		isvalid = isvalid&& false;				
		document.getElementById("username_span").className = "spaninvalid";
	}else{
		document.getElementById("username_span").className = "spanvalid";
	}
	
	// check field password
	if (password.match(/^[A-Za-z0-9_]{8,}$/i) && (password !== username) ){
		document.getElementById("password_span").className = "spanvalid";
	}else{
		isvalid = isvalid&& false;						
		document.getElementById("password_span").className = "spaninvalid";
	}
	
	// check field confirm password
	if (password != confirmpassword){
		isvalid = isvalid&& false;						
		document.getElementById("confirm_span").className = "spaninvalid";
	}else{
		document.getElementById("confirm_span").className = "spanvalid";
	}
	
	// check field nama lengkap
	if (!nama.match(/^[A-Za-z0-9]+[ ]+[A-Za-z0-9]+.*$/i)){
		isvalid = isvalid&& false;				
		document.getElementById("nama_span").className = "spaninvalid";
	}else{
		document.getElementById("nama_span").className = "spanvalid";
	}
	
	// check field tanggal lahir
	if (!tanggal.match(/^[1-9][0-9]{3}-[0-9]{2}-[0-9]{2}[ ]*$/i)){
		isvalid = isvalid&& false;				
		document.getElementById("tanggal_span").className = "spaninvalid";
	}else{
		document.getElementById("tanggal_span").className = "spanvalid";
	}
	// check field jenis kelamin
	var selectedGender  = document.getElementById("gender").selectedIndex;
	if (selectedGender === 0){
		isvalid = isvalid && false;
		document.getElementById("gender_span").className = "spaninvalid";
	}else{
		document.getElementById("gender_span").className = "spanvalid";
	}
	
	
	
	// check field email	
	if (!email.match(/[0-9a-zA-Z\.]+@[a-zA-Z]+\.[a-zA-Z]{2,}/i) && !email.match(/ /i)){
		isvalid = isvalid&& false;				
		document.getElementById("email_span").className = "spaninvalid";
	}else{
		document.getElementById("email_span").className = "spanvalid";
	}
	
	// check avatar		
	if (document.getElementsByName("avatar")[0].value === ""){
		isvalid = isvalid&& false;						
		document.getElementById("avatar_span").className = "spaninvalid";
	}else{
		var ext = (document.getElementsByName("avatar")[0].value ).substr((document.getElementsByName("avatar")[0].value ).lastIndexOf('.') + 1);
		if ((ext=== "jpg" )||(ext === "jpeg")||(ext === "JPEG")||(ext === "JPG")){
			document.getElementById("avatar_span").className = "spanvalid";
		}
		
	}
                
	
	
	if (isvalid){
		// valid
		document.getElementById("daftar").disabled = "";		
		document.getElementById("daftar").className = "daftarenabled";
		document.getElementById("username_span").className = "spanvalid";
		document.getElementById("password_span").className = "spanvalid";
		document.getElementById("confirm_span").className = "spanvalid";
		document.getElementById("nama_span").className = "spanvalid"; 
		document.getElementById("tanggal_span").className = "spanvalid";
		document.getElementById("gender_span").className = "spanvalid";
		document.getElementById("email_span").className = "spanvalid";
		document.getElementById("avatar_span").className = "spanvalid";		
	}else{		
		document.getElementById("daftar").disabled = "disabled";		
		document.getElementById("daftar").className = "daftardisabled";
	}
return true;
}
window.captureEvents(Event.KEYPRESS); 
window.onkeyup = checkForms;

function onRegisterButtonClick(){
	document.location.href = "index.html";
}
